from django.db import models
import uuid

# Create your models here.


class Platform(models.Model):
    name = models.CharField(max_length=20)

    def __str__(self):
        return self.name

class Group(models.Model):
    name = models.CharField(max_length=20)
    platform = models.ForeignKey(Platform,on_delete=models.CASCADE)
    token = models.URLField()

    def __str__(self):
        return self.name

class Tool(models.Model):
    name = models.CharField(max_length=20)
    url = models.GenericIPAddressField()

    def __str__(self):
        return self.name

class Project(models.Model):
    name = models.CharField('项目名',max_length=20);
    
    def __str__(self):
        return self.name

class Webhook(models.Model):
    name = models.CharField('名称',max_length=20);
    project = models.ForeignKey(Project,on_delete=models.CASCADE,verbose_name = '项目')
    platform = models.ManyToManyField(Platform, verbose_name = '平台')
    group = models.ManyToManyField(Group, verbose_name = '群组')
    # group = models.OneToManyField(Group)
    # platform = models.ForeignKey(Platform,on_delete=models.CASCADE)
    # group = models.ForeignKey(Group,on_delete=models.CASCADE)
    tool = models.ForeignKey(Tool,on_delete=models.CASCADE, verbose_name = '工具')
    uuid = models.UUIDField(auto_created=True, default=uuid.uuid4, editable=False)
    def __str__(self):
        return self.name